<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<script type="text/javascript">
$(function(){
	$("#accordion").accordion({
		heightStyle: "fill"
	});
	$( "#accordion-resizer" ).resizable({
      minHeight: 140,
      minWidth: 200,
      resize: function() {
        $( "#accordion" ).accordion( "refresh" );
      }
    });
	var i = 1;
	$(".add_content").click(function(){
		var _html = "<tr>";
		_html += "<td><input type='hidden' name='mid_add" + i + "' value='<?=$module['id']?>' /><?=$module['module_name']?></td>";
		_html += "<td><input type='text' name='title_add" + i + "'  size='12' /></td>";
		_html += "<td><input type='text' name='image_add" + i + "' size='12' /></td>";
		_html += "<td><input type='text' name='price_add" + i + "' size='5' /></td>";
		_html += "<td><input type='text' name='url_add" + i + "' size='20' /></td>";
		_html += "<td><textarea name='content_add" + i + "' rows='1'></textarea></td>";
		_html += "<td><input type='text' name='sort_add" + i + "' size='3' /></td>";
		_html += "<td><a class='del_content'>删除</a></td>";
		_html += "</tr>";
		$(".list_table").append(_html);
		i++;
	});
	$(".del_content").live("click", function(){
		if ( ! confirm("确定删除？"))
		{
			return false;
		}
		else
		{
			$(this).parent().parent().remove();
		}
	});
	$(".refresh_icon").click(function(){
		var url = "<?=url('Online::EbayTemplate/RefreshFilesList')?>&shop_path=<?=$template['shop_path']?>&template_path=<?=$template['path']?>";
		$.ajax({
			url: url,
			type: "GET",
			success:
				function(data)
				{
					var obj = eval(data);
					$('#filelist').contents().remove();
					var html = '';
					for (var i = 0; i< obj.length; i++)
					{
						html += '<div style="float: left; padding-right: 5px;">'
						for (var j = 0; j < obj[i].length; j++)
						{
							html += obj[i][j]+'<br />';
						}
						html += '</div>';
					}
					$('#filelist').append(html);
				}
		});
	});
	$(".upload_icon").click(function(){
		var url = "<?=url('Online::EbayTemplate/Upload', array('id' => $template['id']))?>";
		window.open(url);
	});
});
</script>
<style>
#accordion-resizer {
float: left;
}
</style>
<div style="float: left; padding-right: 10px;">
<h1>模板模块信息列表</h1>
<table class="form_table" width="60%">
<tr>
	<th>所属模板</th>
	<td><strong><?=$template['name']?></strong></td>
	<th>模板路径</th>
	<td><strong><?=$template['path']?></strong></td>
</tr>
<tr>
	<th>所属店铺</th>
	<td><strong><?=$template['shop_name']?></strong></td>
	<th>店铺路径</th>
	<td><strong><?=$template['shop_path']?></strong></td>
</tr>
</table>
<form method="post" action="<?=url('Online::EbayTemplate/TemplateModuleContentEditSave')?>" onsubmit="return Validator.Validate(this,3);">
<table class="list_table">
<tr>
	<th width="60">所属模块</th>
	<th width="60">标题</th>
	<th width="60">图片</th>
	<th width="50">价格</th>
	<th width="60">链接地址</th>
	<th width="100">内容</th>
	<th>排序</th>
	<th>操作</th>
</tr>
<?if ($content):?>
<?foreach ($content as $c):?>
<tr>
	<td><input type="hidden" name="mid_<?=$c['id']?>" value="<?=$c['ebay_template_module_id']?>" /><?=$c['module_name']?></td>
	<td><input type="text" name="title_<?=$c['id']?>" value="<?=$c['title']?>" size="12" /></td>
	<td><input type="text" name="image_<?=$c['id']?>" value="<?=$c['image']?>" size="12" /></td>
	<td><input type="text" name="price_<?=$c['id']?>" value="<?=$c['price']?>" size="5" /></td>
	<td><input type="text" name="url_<?=$c['id']?>" value="<?=$c['url']?>" size="20" /></td>
	<td><textarea name="content_<?=$c['id']?>" rows="1"><?=$c['content']?></textarea></td>
	<td><input type="text" name="sort_<?=$c['id']?>" value="<?=$c['sort']?>" size="3" /></td>
	<td><a class="del_content">删除</a></td>
</tr>
<?endforeach;?>
<?endif;?>
</table>
<a href="<?=url('Online::EbayTemplate/TemplateDetail', array('id' => $_GET['id']))?>">返回上一级</a> |
<a class="add_content">添加内容</a>
<div style="margin-left: 300px;"><input type="submit" class="button" value="保存" /></div>
</form>
</div>
<div id="accordion-resizer">
	<div id="accordion">
		<h3>
			文件列表
			<a class="upload_icon" title="上传"></a>
			<a class="refresh_icon" title="刷新"></a>
		</h3>
	    <div id="filelist">
		<?foreach (array_chunk(Helper_BSS_Normal::getDirlist(Q::ini('custom_system/ebay_template_local_dir') . $template['shop_path'] . '/' . $template['path']), 27, true) as $f):?>
			<div style="float: left; padding-right: 5px;">
			<?foreach ($f as $v):?>
			<?=$v?><br />
			<?endforeach;?>
			</div>
		<?endforeach;?>
		</div>
	</div>
</div>
<?php $this->_endblock();?>